package cn.codergege.demo.controller;

import cn.codergege.demo.domain.primary.Person;
import cn.codergege.demo.service.PersonService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/person")
public class PersonController {
    private final Logger log = LoggerFactory.getLogger(PersonController.class);

    @Autowired
    private PersonService personService;

    @RequestMapping("/people")
    private Object listAll() {
        List<Person> people = personService.getAllPersons();
        System.out.println("------------------------------------> " + people.size());
        return people;
    }

    @RequestMapping(value = "/person", method = RequestMethod.POST)
    private void add(@RequestBody Person person) {
        System.out.println("------------------------------------> " + person);
        personService.save(person);
    }

}
